package com.backtracking;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Solution05 {
    List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if (digits.length() == 0 || digits == null) return res;
        String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        backTracking(numString,digits,0);
        return res;
    }

    StringBuilder sb = new StringBuilder();
    public void backTracking(String[] numString,String digists,int index) {
        if (index == digists.length()) {
            res.add(sb.toString());
            return;
        }
        String str = numString[digists.charAt(index)-'0'];
        for (int i = 0; i < str.length(); i++) {
            sb.append(str.charAt(i));
            backTracking(numString,digists,index+1);
            sb.deleteCharAt(sb.length()-1);
        }
    }
}
